<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.global.js"></script>
  </head>

  <body>
    <div id="app">
      <div id="dynamicexample">
        <h2>Scroll down the page</h2>
        <input type="range" min="0" max="500" v-model="pinPadding" />
        <p v-pin:[direction]="pinPadding">
          Stick me {{ pinPadding + 'px' }} from the {{ direction || 'top' }} of
          the page
        </p>
      </div>
    </div>
    <script>
      const app = Vue.createApp({
        data() {
          return {
            direction: "right",
            pinPadding: 200,
          };
        },
      });

      /* mounted和updated处理逻辑相同时 可以不必写生命周期钩子 简写如下*/
      app.directive("pin", (el, binding) => {
        el.style.position = "fixed";
        const s = binding.arg || "top";
        el.style[s] = binding.value + "px";
      });

      const vm = app.mount("#app");
    </script>
  </body>
</html>
